home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / adg_7_8.zip / SHEET.C < prev    next >
C/C++ Source or Header  |  1991-02-21  |  9KB  |  257 lines

  1. /****************************************************************************
  2. Module name: Sheet.C
  3. Programmer : Jeffrey M. Richter & Elvira Peretsman.
  4. *****************************************************************************/
  5.  
  6. #include "..\nowindws.h"
  7. #undef NOCOLOR
  8. #undef NOGDI
  9. #undef NOKERNEL
  10. #undef NOLSTRING
  11. #undef NOMB
  12. #undef NOMDI
  13. #undef NOMENUS
  14. #undef NOUSER
  15. #undef NOWINMESSAGES
  16. #undef NOWINOFFSETS
  17. #include <windows.h>
  18.  
  19. #include "mdi.h"
  20.  
  21. static char _szClassName[] = "Sheet";
  22.  
  23. typedef struct {
  24.    HMENU hMenu;
  25.    HANDLE hAccelTable;
  26. } CLSEB;
  27.  
  28.  
  29. LONG FAR PASCAL SheetProc (HWND hWnd, WORD wMsg, WORD wParam, LONG lParam) {
  30.    BOOL fCallDefProc = FALSE;
  31.    DWORD dwResult = 0;
  32.    WORD wTemp = 0;
  33.    HMENU hMenu;
  34.    char szBuf[100], szString[100], szCaption[25];
  35.  
  36.    switch (wMsg) {
  37.       case WM_CREATE:
  38.          // If this window is first instance created of this class.
  39.          if (GETCLSEB(hWnd, CLSEB, hMenu) == NULL) {
  40.  
  41.             // Initialize the menu and accelerator handles for this class.
  42.             wTemp = LoadMenu(_hInstance, _szClassName);
  43.             SETCLSEB(hWnd, CLSEB, hMenu, (HMENU) wTemp);
  44.             wTemp = LoadAccelerators(_hInstance, _szClassName);
  45.             SETCLSEB(hWnd, CLSEB, hAccelTable, (HANDLE) wTemp);
  46.          }
  47.          break;
  48.  
  49.       case WM_MDIACTIVATE: 
  50.          if (wParam == FALSE) break;
  51.  
  52.          // Child is being activated.
  53.  
  54.          // Set the menu bar and the accelerators to the appropriate ones
  55.          // for this window class.
  56.          ChangeMDIMenu(GETFRAME(hWnd), GetParent(hWnd),
  57.             (HMENU) GETCLSEB(hWnd, CLSEB, hMenu), IDM_WINDOWTILEVERT);
  58.          _hAccelTable = (HANDLE) GETCLSEB(hWnd, CLSEB, hAccelTable);
  59.  
  60.          // For the Status bar at the bottom of the Frame window to be 
  61.          // updated for this child's information.
  62.          InvalidateRect(GETFRAME(hWnd), NULL, TRUE);
  63.          break;
  64.  
  65.       case WM_CLOSE:
  66.          // Make sure that it is OK to close this child window.
  67.          fCallDefProc = (BOOL) SendMessage(hWnd, WM_QUERYENDSESSION, TRUE, 0);
  68.          if (fCallDefProc) SendMessage(hWnd, WM_ENDSESSION, TRUE, 0);
  69.          break;
  70.  
  71.       case WM_QUERYENDSESSION:
  72.          // Prompt user whether to save changes to this document.
  73.          // Usually, a dirty flag (stored in the window's extra bytes
  74.          // is used to determine if it is necessary to ask this question).
  75.  
  76.          // Construct string including the document's name.
  77.          lstrcpy(szBuf, "Save changes to ");
  78.          wTemp = lstrlen(szBuf);
  79.          GetWindowText(hWnd, szBuf + wTemp, sizeof(szBuf) - wTemp);
  80.          lstrcat(szBuf, "?");
  81.  
  82.          // Display message box to user.  The message box should 
  83.          // be system modal if the entire Windows session is being 
  84.          // terminated. (wParam is FALSE).
  85.          wTemp = MessageBox(hWnd, szBuf, _szAppName,
  86.             MB_ICONQUESTION | MB_YESNOCANCEL |
  87.             (wParam ? MB_APPLMODAL : MB_SYSTEMMODAL));
  88.  
  89.          switch (wTemp) {
  90.             case IDYES:
  91.                // Save the document and it's OK to quit.
  92.                dwResult = TRUE;
  93.                break;
  94.  
  95.             case IDNO:
  96.                // Don't save the document and it's OK to quit.
  97.                dwResult = TRUE;
  98.                break;
  99.  
  100.             case IDCANCEL:
  101.                // Don't save the document and it's NOT OK to quit.
  102.                dwResult = FALSE;
  103.                break;
  104.          }
  105.          break;
  106.  
  107.       case WM_ENDSESSION:
  108.          // Do any last minute cleanup during this message.
  109.          break;
  110.  
  111.       case WM_DESTROY:
  112.          // Notify the Frame window that a child has been destroyed after 
  113.          // the child is actually destroyed.  (That's why we use
  114.          // PostMessage instead of SendMessage here).
  115.          PostMessage(GETFRAME(hWnd), FW_MDICHILDDESTROY, hWnd, 0);
  116.          fCallDefProc = TRUE;
  117.          break;
  118.  
  119.       case AC_PAINTSTATBAR:
  120.          // Message sent by the Frame window when the status bar needs to 
  121.          // be repainted.
  122.          // wParam = HDC, lParam = LPPAINTSTRUCT to status area in frame.
  123.  
  124.          // Construct status bar string for display.
  125.          LoadString(_hInstance, IDS_SHEETSTATUSBAR, szBuf, sizeof(szBuf));
  126.  
  127.          // Draw the horizontal dividing line separating the Status bar
  128.          // from the MDICLIENT window.
  129.          ((LPPAINTSTRUCT) lParam)->rcPaint.top += (int) 
  130.             SendMessage(GETFRAME(hWnd), FW_DRAWSTATUSDIVIDE, 0,
  131.             (LONG) (LPPAINTSTRUCT) lParam);
  132.          
  133.          // Paint the text in the status bar.
  134.          TextOut((HDC) wParam, 0, ((LPPAINTSTRUCT) lParam)->rcPaint.top,
  135.             szBuf, lstrlen(szBuf));
  136.          break;
  137.  
  138.       case WM_MENUSELECT:
  139.          // Normally, only MDI Child system menu options could appear
  140.          // in this message.  But the Frame window forces WM_MENUSELECT
  141.          // messages to appear here whenever a menu selection occurs.
  142.  
  143.          if (lParam == MAKELONG(-1, 0)) {
  144.             // User has stopped using the menu system.  Notify Frame window
  145.             // so that the status bar will be invalidated.
  146.             SendMessage(GETFRAME(hWnd), FW_SETMENUHELP, 0, 0);
  147.             break;
  148.          }
  149.  
  150.          switch (LOWORD(lParam) & (MF_POPUP | MF_SYSMENU)) {
  151.  
  152.             case 0:
  153.                // wParam is a menu item ID NOT on the Child's system menu.
  154.  
  155.                // If wParam is any of the MDI Children listed in the 
  156.                // "Window" menu, display the same help text.
  157.                if ((wParam > IDM_WINDOWCHILD) && (wParam <= IDM_WINDOWCHILD + 9))
  158.                   wParam = IDM_WINDOWCHILD;
  159.  
  160.                // Tell the Frame that this window should display the help
  161.                // text and the identifier for the help text.
  162.                wTemp = IDS_SHEETMENUID + wParam;
  163.                break;
  164.  
  165.             case MF_POPUP:
  166.                // wParam is handle to popup menu.
  167.                // Calculate the index of the top-level menu.
  168.                hMenu = GetMenu(GETFRAME(hWnd));
  169.                wTemp = GetMenuItemCount(hMenu);
  170.                while (wTemp--) 
  171.                   if (GetSubMenu(hMenu, wTemp) == (HMENU) wParam) break;
  172.                wTemp += IDS_SHEETPOPUPID;
  173.                if (!IsZoomed(hWnd)) wTemp++;
  174.                break;
  175.  
  176.             case MF_SYSMENU:
  177.                // wParam is menu item ID from MDI Child's system menu.
  178.                wTemp = IDS_SHEETMENUID + ((wParam & 0x0FFF) >> 4);
  179.                break;
  180.  
  181.             case MF_POPUP | MF_SYSMENU:
  182.                // wParam is handle to MDI Child's sys menu.
  183.                wTemp = IDS_SHEETPOPUPID;
  184.                break;
  185.          }
  186.          // Tell the Frame that this window should display the help
  187.          // text and the identifier for the help text.
  188.          SendMessage(GETFRAME(hWnd), FW_SETMENUHELP, hWnd, wTemp);
  189.          break;
  190.  
  191.       case WM_ENTERIDLE:
  192.          // User stopped moving around in the help system, make the Frame
  193.          // believe that it received this message directly.
  194.          SendMessage(GETFRAME(hWnd), wMsg, wParam, lParam);
  195.          break;
  196.  
  197.       case AW_PAINTMENUHELP:
  198.          // Message sent from Frame window to notify child that it should
  199.          // paint the status bar text for the last highlighted menu item.
  200.          // lParam = LPPAINTSTRUCT of Frame's status bar.
  201.  
  202.          // Ask the Frame window what the last selected menu ID was.
  203.          // This value was sent to the frame by this window during the 
  204.          // processing for the WM_MENUSELECT message.
  205.          dwResult = SendMessage(GETFRAME(hWnd), FW_GETMENUHELP, 0, 0);
  206.  
  207.          // Draw the horizontal dividing line separating the Status bar
  208.          // from the MDICLIENT window.
  209.          ((LPPAINTSTRUCT) lParam)->rcPaint.top += (int) 
  210.             SendMessage(GETFRAME(hWnd), FW_DRAWSTATUSDIVIDE, 0,
  211.             (LONG) (LPPAINTSTRUCT) lParam);
  212.  
  213.          // Construct the string that is to be displayed.
  214.          LoadString(_hInstance, LOWORD(dwResult), szString, sizeof(szString));
  215.          GetWindowText(hWnd, szCaption, sizeof(szCaption));
  216.          wsprintf(szBuf, szString, (LPSTR) szCaption);
  217.  
  218.          // Paint the menu help text in the status bar.
  219.          TextOut(((LPPAINTSTRUCT) lParam)->hdc,
  220.             0, ((LPPAINTSTRUCT) lParam)->rcPaint.top, szBuf, lstrlen(szBuf));
  221.          break;
  222.  
  223.       case WM_COMMAND:
  224.          // Any menu options NOT processed by the Frame are passed to the
  225.          // active child.
  226.          MessageBox(hWnd, "Option not implemented.", _szAppName, MB_OK);
  227.          break;
  228.  
  229.       default: fCallDefProc = TRUE; break;
  230.    }
  231.  
  232.    if (fCallDefProc)
  233.       dwResult = DefMDIChildProc(hWnd, wMsg, wParam, lParam);
  234.  
  235.    return(dwResult);
  236. }
  237.  
  238.  
  239. BOOL FAR PASCAL RegisterSheetWndClass (void) {
  240.    WNDCLASS wc;
  241.  
  242.    wc.style          = 0;
  243.    wc.lpfnWndProc    = SheetProc;
  244.  
  245.    // Number of class extra bytes used by structure.
  246.    wc.cbClsExtra     = sizeof(CLSEB);
  247.  
  248.    wc.cbWndExtra     = 0;
  249.    wc.hInstance      = _hInstance;
  250.    wc.hIcon          = LoadIcon(_hInstance, _szClassName);
  251.    wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
  252.    wc.hbrBackground  = COLOR_WINDOW + 1;
  253.    wc.lpszMenuName   = NULL;
  254.    wc.lpszClassName  = _szClassName;
  255.    return(RegisterClass(&wc));
  256. }
  257.